<!-- 已法查询 -->
<template>
	<view>
		<view>
			<bg-tab :tabs="tabs" :current="current" @tab-change="tabChange"></bg-tab>
				
			<view class="p-3">
				<view v-if="current==0">
					<view class="bt-block">
						<u-list  v-if="dataList.length>0" @scrolltolower="loadMore" style="height:calc(100vh - 420rpx)">
							<bg-cell >
								项目名称
							</bg-cell>
							<bg-cell :border="idx<dataList.length-1" v-for="p,idx in dataList" showArrow="true" @click="gotoDetail(1, p)"> 
								<view class="font-12 font-bold">{{p.projectName}}</view>
							</bg-cell>
						</u-list>
						<u-empty v-else></u-empty>
					</view>
				</view>
				<view v-else >
					<u-list v-if="dataList.length>0" @scrolltolower="loadMore" style="height:calc(100vh - 360rpx)">
						<borrow-item v-for="i, idx in dataList" :item="i" :key="idx" @click="gotoDetail(2, i)"></borrow-item>
					</u-list>
					<u-empty v-else></u-empty>
				</view>
			</view>
			
			<view class="bt-footer">
				<view class="w-100 text-center">
					<view class="font-12 text-grey1 mb-3">共计 {{total}} 条</view>
					<bg-btn style="background-color: #ffefe7;color:#EE3636;">
						共计已发放薪资金额：{{totalAmount}}元
					</bg-btn>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import borrowItem from './components/borrow-item.vue'
	import {alreadySend ,alreadySendTotal} from "@/api/apply.js"
	import {alreadyToSend, alreadyToSendTotal} from "@/api/salary.js"
	export default {
		components:{borrowItem},
		data() {
			return {
				current:0,
				tabs:['薪资发放','借支已发'],
				params:{
					pageNum:1,
					pageSize:20
				},
				dataList:[],
				totalAmount:'',
				total:'',
			}
		},
		mounted() {
			this.getSend()
		},
		methods: {
			tabChange(e){
				this.current = e
				this.dataList = []
				this.total = 0
				this.params.pageNum = 1
				if(this.current == 0){
					this.getSend()
				} else {
					this.getToSend()
				}
			},
			getSend(){
				alreadySend(this.params).then(res=>{
					this.dataList = [...this.dataList, ...res.data.rows]
					this.total = res.data.total
				})
				alreadySendTotal().then(res=>{
					this.totalAmount = res.data
				})
			},
			getToSend(){
				alreadyToSend(this.params).then(res=>{
					this.dataList = [...this.dataList, ...res.data.rows]
					this.total = res.data.total
				})
				alreadyToSendTotal().then(res=>{
					this.totalAmount = res.data
				})
			},
			gotoDetail(idx ,item) {
				if(idx==1){
					uni.navigateTo({
						url:"/pages/project/grant/detail?pid="+item.projectId+ "&type=yf"
					})
				}else{
					uni.navigateTo({
						url:"/pages/project/grant/borrow-doc?bid="+item.id
					})
				}
			}
		}
	}
</script>

<style>

</style>
